@extends('layouts.userctl')
@section('content')
<style>
	.layui-card-header {
		margin-top: 15px;
	}

	/*.layui-table-cell {
		display: flex;
		justify-content: center;
		align-items: center;
	}*/

	.userstatus {
		margin-left: 6px;
		color: #888;
		font-size: 14px;
	}

	.layui-table-tips-c::before {
		position: absolute !important;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0px !important;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.layui-table-cell {
		height: auto !important;
	}

	.laytable-cell-1-0-0 {
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.layui-tab-brief>.layui-tab-title .layui-this {
	    color: #26a54a !important;
	}
</style>
{{csrf_field()}}
<div class="layuimini-container">
	<div class="layuimini-main">
		
		<div style="margin: 10px 10px 10px 10px" id="btn">
			<form class="layui-form layui-form-pane" action="">
				<div class="layui-form-item">
					<div class="layui-inline" style="float: left;">
						<!-- <a class="layui-btn layui-btn-normal" href="{{route('admin.demand.dangerlist')}}?type={{$comNameType}}"
							style="color: #fff;">{{$comName}}</a> -->
						<!--						<a href="{{ url()->previous() }}" class="layui-btn layui-btn-primary">返 回</a>-->
						<a class="layui-btn layui-btn-normal" href="{{route('admin.demand.exportone')}}?type={{$type}}"
							style="color: #fff;"><i class="layui-icon layui-icon-addition"></i>导 出</a>
					</div>
				</div>
			</form>	
		</div>
		<div class="layui-tab layui-tab-brief">
			<ul class="layui-tab-title">
				<li class="layui-this">隐患排查</li>
				<li>应急物资</li>
			</ul>
			<div class="layui-tab-content" style="height: 100px;">
				<div class="layui-tab-item layui-show"><table class="layui-table layui-hide" id="dataTable" lay-filter="dataTable"></table></div>
				<div class="layui-tab-item"><table class="layui-table layui-hide" id="dataTable2" lay-filter="dataTable2"></table></div>
			</div>
		</div>
		<!--注意此处table标签里的id-->
		
	</div>
</div>

<!-- <div class="layui-card">
	<div class="layui-card-header layuiadmin-card-header-auto">
		<a class="layui-btn layui-btn-normal" href="{{route('admin.user.adduser')}}" style="color: #fff;">新增用户</a>
	</div>
	<div class="layui-card-body">
		<table id="dataTable" lay-filter="dataTable"></table>
	</div>
</div> -->

<script>
	layui.use(['layer', 'table', 'form'], function() {
		var layer = layui.layer
		var form = layui.form
		var table = layui.table
		//用户表格初始化
		var dataTable = table.render({
			elem: '#dataTable',
			height: 'full',
			limit: 10,
			url: '/admin/demand/dangerlistdata?type=1',
			page: true,
			cols: [
				[ //表头
					{ field: 'id', title: '序  号' },
					{ field: 'company_title', title: '公司名称' },
					{ field: 'title', title: '标  题' },
					{ field: 'content', title: '内  容' },
					{ field: 'reply_content', title: '回复内容' },
					{ field: 'time', title: '创建时间' },
					{ field: 'reply_time', title: '回复时间' },
					{
						title: '操  作',
						templet: function(d) {
							return '<a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="replay">回 复</a>'

						}
					},
				]
			],
			done: function(response) { //定位当前table视图
				//动态监听表头高度变化，冻结行跟着改变高度
				$('.layui-table-header  tr').resize(function() {
					$('.layui-table-header  tr').each(function(index, val) {
						$($('.layui-table-fixed .layui-table-header table tr')[index])
							.height($(val).height())
					})
				})
				//初始化高度，使得冻结行表头高度一致
				$('.layui-table-header  tr').each(function(index, val) {
					$($('.layui-table-fixed .layui-table-header table tr')[index]).height($(
						val).height())
				})

				//表体部分
				//动态监听表体高度变化，冻结行跟着改变高度
				$('.layui-table-body  tr').resize(function() {
					$('.layui-table-body  tr').each(function(index, val) {
						$($('.layui-table-fixed .layui-table-body table tr')[index])
							.height($(val).height())
					})
				})
				//初始化高度，使得冻结行表体高度一致
				$('.layui-table-body  tr').each(function(index, val) {
					$($('.layui-table-fixed .layui-table-body table tr')[index]).height($(val)
						.height())
				})
				var tableView = this.elem.next()

				//response.data获取后端返  回的JSON格式数据
				$.each(response.data, function(index, item) {

					//逻辑判断
					if (item.is_delete == '0') {
						//改变TR标签内字体颜色
						tableView.find('tbody tr[data-index="' + index + '"]').css('color',
							'#FF0033')
					}
				})
			}
		})
		var dataTable2 = table.render({
			elem: '#dataTable2',
			height: 'full',
			limit: 10,
			url: '/admin/demand/dangerlistdata?type=2',
			page: true,
			cols: [
				[ //表头
					{ field: 'id', title: '序  号' },
					{ field: 'company_title', title: '公司名称' },
					{ field: 'title', title: '标  题' },
					{ field: 'content', title: '内  容' },
					{ field: 'reply_content', title: '回复内容' },
					{ field: 'time', title: '创建时间' },
					{ field: 'reply_time', title: '回复时间' },
					{
						title: '操  作',
						templet: function(d) {
							return '<a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="replay">回 复</a>'
		
						}
					},
				]
			],
			done: function(response) { //定位当前table视图
				//动态监听表头高度变化，冻结行跟着改变高度
				$('.layui-table-header  tr').resize(function() {
					$('.layui-table-header  tr').each(function(index, val) {
						$($('.layui-table-fixed .layui-table-header table tr')[index])
							.height($(val).height())
					})
				})
				//初始化高度，使得冻结行表头高度一致
				$('.layui-table-header  tr').each(function(index, val) {
					$($('.layui-table-fixed .layui-table-header table tr')[index]).height($(
						val).height())
				})
		
				//表体部分
				//动态监听表体高度变化，冻结行跟着改变高度
				$('.layui-table-body  tr').resize(function() {
					$('.layui-table-body  tr').each(function(index, val) {
						$($('.layui-table-fixed .layui-table-body table tr')[index])
							.height($(val).height())
					})
				})
				//初始化高度，使得冻结行表体高度一致
				$('.layui-table-body  tr').each(function(index, val) {
					$($('.layui-table-fixed .layui-table-body table tr')[index]).height($(val)
						.height())
				})
				var tableView = this.elem.next()
		
				//response.data获取后端返  回的JSON格式数据
				$.each(response.data, function(index, item) {
		
					//逻辑判断
					if (item.is_delete == '0') {
						//改变TR标签内字体颜色
						tableView.find('tbody tr[data-index="' + index + '"]').css('color',
							'#FF0033')
					}
				})
			}
		})
		$('#searchbtn').click(function() {
			dataTable.reload({
				where: { keyword: $('#keywordinput').val() },
				page: { curr: 1 }
			})
		})
		$(document).on('click', '.smimg', function() {
			var url = $(this).attr('src')
			var img = '<img src=\'' + url +
				'\' style=\'width:800px;height:auto;max-height:800px;background-color:#fff;\'/>'
			layer.open({
				type: 1,
				title: false,
				scrollbar: false,
				area: ['800px', 'auto'],
				skin: 'layui-layer-nobg', //没有背景色
				shadeClose: true,
				content: img
			})
		})
		//监听工具条
		table.on('tool(dataTable)', function(obj) { //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
			var data = obj.data //获得当前行数据
				,
				layEvent = obj.event //获得 lay-event 对应的值
			if (layEvent === 'export') {
				location.href = data.url
			} else if (layEvent === 'replay') {
				location.href = '/admin/demand/replay?type=1&&id=' + data.id
			}
		})
		table.on('tool(dataTable2)', function(obj) { //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
			var data = obj.data //获得当前行数据
				,
				layEvent = obj.event //获得 lay-event 对应的值
			if (layEvent === 'export') {
				location.href = data.url
			} else if (layEvent === 'replay') {
				location.href = '/admin/demand/replay?type=2&&id=' + data.id
			}
		})
	})
</script>
@endsection
